package eu.best.sercheng.frontier;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;


public class Frontier implements IFrontiere
{ 
	private List<String> cache;
	private Queue<URL> urlQueue;
	
	public Frontier() {
		cache = new ArrayList<String>(); 
		urlQueue = new ConcurrentLinkedQueue<URL>();
	}
	
	@Override
	public synchronized URL getLink() {
		return urlQueue.poll();
	}

	@Override
	public synchronized void pushLink(List<URL> list) {
		for(URL url: list) {
			String urlString = url.toExternalForm();
			if(cache.contains(urlString) == true) {
				//Nothing happends - url was visited
			}
			else {
				urlQueue.add(url);
				cache.add(url.toExternalForm());
			}
		}
		
	}

}
